﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Entity;
using System.Data.Common;

namespace Jlob.OpenErpNet.EFProvider.Test
{
    [TestClass]
    public class OpenErpConnectionTest
    {
        [TestMethod]
        public void Test_Connection_Open()
        {
            DbContext nwEntities = new TestContext("name=OpenErpConnection");
            DbConnection con = nwEntities.Database.Connection;
            con.Open();
            Assert.AreEqual(con.State, System.Data.ConnectionState.Open);
        }

        [TestMethod]
        public void Test_Connection_NOTFOUND_Exception()
        {
            bool exceptionRaised = false;
            DbContext nwEntities = new TestContext("name=OpenErpConnectionFail1");
            DbConnection con = nwEntities.Database.Connection;
            try
            {
                con.Open();
            }
            catch (System.Net.WebException ex)
            {
                exceptionRaised = true;
            }
            Assert.IsTrue(exceptionRaised);
        }

        [TestMethod]
        public void Test_Connection_Refused()
        {
            bool exceptionRaised = false;
            DbContext nwEntities = new TestContext("name=OpenErpConnectionFail2");
            DbConnection con = nwEntities.Database.Connection;
            try
            {
                con.Open();
            }
            catch (System.Net.WebException ex)
            {
                exceptionRaised = true;
            }
            Assert.IsTrue(exceptionRaised);
        }
    }
}
